package com.mob.tools.gui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.RectF;
import android.os.Handler.Callback;
import android.os.Message;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import com.mob.tools.MobLog;
import com.mob.tools.log.NLog;
import com.mob.tools.utils.BitmapHelper;
import com.mob.tools.utils.UIHandler;
import java.util.Random;

public class AsyncImageView extends ImageView
  implements BitmapProcessor.BitmapCallback, Handler.Callback
{
  private static final int MSG_IMG_GOT = 1;
  private static final Random rnd = new Random();
  private Bitmap defaultBm;
  private int defaultRes;
  private Path path;
  private float[] rect;
  private boolean scaleToCrop;
  private String url;

  public AsyncImageView(Context paramContext)
  {
    super(paramContext);
    init(paramContext);
  }

  public AsyncImageView(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    init(paramContext);
  }

  public AsyncImageView(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    init(paramContext);
  }

  private int[] getSize()
  {
    int i = getWidth();
    int j = getHeight();
    if ((i == 0) || (j == 0))
    {
      ViewGroup.LayoutParams localLayoutParams = getLayoutParams();
      if (localLayoutParams != null)
      {
        i = localLayoutParams.width;
        j = localLayoutParams.height;
      }
    }
    if ((i == 0) || (j == 0))
    {
      measure(0, 0);
      i = getMeasuredWidth();
      j = getMeasuredHeight();
    }
    return new int[] { i, j };
  }

  private Bitmap goCrop(Bitmap paramBitmap)
  {
    float f1 = paramBitmap.getWidth();
    float f2 = paramBitmap.getHeight();
    if ((f1 == 0.0F) || (f2 == 0.0F))
      return paramBitmap;
    int[] arrayOfInt1 = getSize();
    if ((arrayOfInt1[0] == 0) || (arrayOfInt1[1] == 0))
      return paramBitmap;
    float f3 = f1 * arrayOfInt1[1] / arrayOfInt1[0];
    if (f3 == f2)
      return paramBitmap;
    int[] arrayOfInt2 = new int[4];
    if (f3 < f2)
    {
      arrayOfInt2[1] = ((int)((f2 - f3) / 2.0F));
      arrayOfInt2[3] = arrayOfInt2[1];
    }
    try
    {
      while (true)
      {
        Bitmap localBitmap = BitmapHelper.cropBitmap(paramBitmap, arrayOfInt2[0], arrayOfInt2[1], arrayOfInt2[2], arrayOfInt2[3]);
        paramBitmap = localBitmap;
        return paramBitmap;
        arrayOfInt2[0] = ((int)((f1 - f2 * arrayOfInt1[0] / arrayOfInt1[1]) / 2.0F));
        arrayOfInt2[2] = arrayOfInt2[0];
      }
    }
    catch (Throwable localThrowable)
    {
      while (true)
        MobLog.getInstance().w(localThrowable);
    }
  }

  private void init(Context paramContext)
  {
    if (isInEditMode())
    {
      setBackgroundColor(-16777216);
      return;
    }
    BitmapProcessor.prepare(paramContext);
  }

  public void execute(String paramString, int paramInt)
  {
    this.url = paramString;
    this.defaultRes = paramInt;
    if (TextUtils.isEmpty(paramString))
    {
      setImageResource(paramInt);
      return;
    }
    Bitmap localBitmap = BitmapProcessor.getBitmapFromCache(paramString);
    if ((localBitmap != null) && (!localBitmap.isRecycled()))
    {
      setBitmap(localBitmap);
      return;
    }
    if (paramInt > 0)
      setImageResource(paramInt);
    BitmapProcessor.process(paramString, this);
  }

  public void execute(String paramString, Bitmap paramBitmap)
  {
    this.url = paramString;
    this.defaultBm = paramBitmap;
    if (TextUtils.isEmpty(paramString))
    {
      setImageBitmap(paramBitmap);
      return;
    }
    Bitmap localBitmap = BitmapProcessor.getBitmapFromCache(paramString);
    if ((localBitmap != null) && (!localBitmap.isRecycled()))
    {
      setBitmap(localBitmap);
      return;
    }
    if ((paramBitmap != null) && (!paramBitmap.isRecycled()))
      setImageBitmap(paramBitmap);
    BitmapProcessor.process(paramString, this);
  }

  public boolean handleMessage(Message paramMessage)
  {
    if (paramMessage.what == 1)
    {
      Object localObject1 = ((Object[])(Object[])paramMessage.obj)[0];
      Object localObject2 = ((Object[])(Object[])paramMessage.obj)[1];
      if ((localObject2 != null) && (localObject1 != null) && (localObject1.equals(this.url)))
        setImageBitmap((Bitmap)localObject2);
    }
    else
    {
      return false;
    }
    if ((this.defaultBm != null) && (!this.defaultBm.isRecycled()))
    {
      setImageBitmap(this.defaultBm);
      return false;
    }
    setImageResource(this.defaultRes);
    return false;
  }

  protected void onDraw(Canvas paramCanvas)
  {
    if (this.rect != null)
    {
      if (this.path == null)
      {
        int i = getWidth();
        int j = getHeight();
        this.path = new Path();
        RectF localRectF = new RectF(0.0F, 0.0F, i, j);
        this.path.addRoundRect(localRectF, this.rect, Path.Direction.CW);
      }
      paramCanvas.clipPath(this.path);
    }
    super.onDraw(paramCanvas);
  }

  public void onImageGot(String paramString, Bitmap paramBitmap)
  {
    Bitmap localBitmap = null;
    if (paramString != null)
    {
      int i = paramString.trim().length();
      localBitmap = null;
      if (i > 0)
      {
        boolean bool = paramString.equals(this.url);
        localBitmap = null;
        if (bool)
          localBitmap = paramBitmap;
      }
    }
    if ((localBitmap != null) && (this.scaleToCrop))
      localBitmap = goCrop(localBitmap);
    Message localMessage = new Message();
    localMessage.what = 1;
    localMessage.obj = new Object[] { paramString, localBitmap };
    UIHandler.sendMessageDelayed(localMessage, rnd.nextInt(300), this);
  }

  public void setBitmap(Bitmap paramBitmap)
  {
    if (this.scaleToCrop)
      paramBitmap = goCrop(paramBitmap);
    setImageBitmap(paramBitmap);
  }

  public void setRound(float paramFloat)
  {
    setRound(paramFloat, paramFloat, paramFloat, paramFloat);
  }

  public void setRound(float paramFloat1, float paramFloat2, float paramFloat3, float paramFloat4)
  {
    this.rect = new float[] { paramFloat1, paramFloat1, paramFloat2, paramFloat2, paramFloat3, paramFloat3, paramFloat4, paramFloat4 };
  }

  public void setScaleToCropCenter(boolean paramBoolean)
  {
    this.scaleToCrop = paramBoolean;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.tools.gui.AsyncImageView
 * JD-Core Version:    0.6.2
 */